package acceptanceTests.promoteUser;

import server.ForumServer;

public class PromoteUserProxy implements PromoteUserInt {

	private PromoteUserImp _real;
	private int _user1Rank;
	private int _user2Rank ;
	
	public PromoteUserProxy(ForumServer server){
		this._real = new PromoteUserImp(server);
		this._user1Rank = 1;
		this._user2Rank = 1;
	}
	
	public boolean Promote(String admin, String member) {
		if (_real.is_implementedPromote()){
			return _real.Promote(admin, member);
		}
		else{
			if(this.rank(admin) < 3) return false;
			else {
				this.upRank(member);
				return true;
			}
		}
	}
	

	private void upRank(String member) {
		if (member.equals("user1")){
			if (this._user1Rank <3){
				this._user1Rank++;
			}
		}
		else if (member.equals("user2")){
			if (this._user2Rank <3){
				this._user2Rank++;
			}
		} 	
	}


	private int rank(String member) {
		if (member.equals("user1")){
			return this._user1Rank;
		}
		else if (member.equals("user2")){
			return this._user2Rank;
		} 
		else return 0;
	}
	

	public boolean isAdmin(String user) {
		// TODO Auto-generated method stub
		if (_real.is_implementedIsAdmin()){
			return _real.isAdmin(user);
		}
		else{
			return (this.rank(user)==3);
		}
	}

	public boolean isModerator(String user) {
		// TODO Auto-generated method stub
		if (_real.is_implementedIsModerator()){
			return _real.isModerator(user);
		}
		else{
			return (this.rank(user)==2);
		}
	}

	public boolean setAdmin(String user) {
		// TODO Auto-generated method stub
		if (_real.is_implementedSetAdmin()){
			return _real.setAdmin(user);
		}
		else{
			if(user.equals("user1")) this._user1Rank=3;
			else if(user.equals("user2")) this._user2Rank=3; 
		}
		return true;
	}
}
